<?php
namespace App\Http\Middleware;

use Closure;

class CheckAdmin
{
    /**
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (session('token') == false) {
            if ($request->ajax()) {
                return response('Unauthorized.', 401);
            } else {
                return response(view('admin.login'));
            }
        }
        return $next($request);
    }
}
